<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('请假审批')"/>
    <style>

        .mainBox {
            width: 90%;
            margin-top: 20px;
            position: absolute;
            top: 0px;
            left: 0px;
            bottom: 50px;
            overflow: auto;
        }

        .bottom {
            width: 100%;
            position: absolute;
            bottom: 0px;
            left: 0px;
            height: 50px;
            line-height: 50px;
            background-color: #F8F8F8;
            border-top: 1px solid #eee;
        }

        .button-container {
            position: absolute;
            right: 15px;
        }
        body{
            background-color: #fff;
        }

        @media (max-width: 600px) {
            .layui-form-item .layui-input-inline{
                width: 100px;
                margin-right: 30px;
            }
            .date {
                width: 120px;
            }
            .date-flag {
                width: 90px;
            }
        }
        @media (max-width: 460px) {
            .date {
                width: auto;
            }
            .date-flag {
                width: auto;
            }
        }
    </style>
</head>
<body>
<form class="layui-form" th:object="${leave}">
    <div class="mainBox">
        <div class="main-container">
            <input name="id" th:field="*{id}" type="hidden">
            <input type="hidden" name="userId" th:field="*{userId}"/>
            <input type="hidden" name="auditId" />
            <div class="layui-form-item">
                <label class="layui-form-label">流程标题</label>
                <div class="layui-input-block">
                    <input type="text" id="processTitle" name="processTitle" th:field="*{processTitle}"
                           readonly class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">请假人工号</label>
                <div class="layui-input-block">
                    <input type="text" id="userSn" name="userSn" th:field="*{userSn}"
                           readonly class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">请假人名称</label>
                <div class="layui-input-block">
                    <input type="text" name="username" th:field="*{username}"
                           readonly class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">假别id</label>
                <div class="layui-input-block">
                    <input type="text" name="leaveTypeName" th:field="*{leaveTypeName}"
                           readonly class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">开始日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="startDateStr" th:field="*{startDateStr}"
                               readonly class="layui-input date" />
                    </div>
                    <div class=" date-flag layui-input-inline">
                        <select name="startDateFlag" disabled>
                            <option value="am" th:selected="*{startDateFlag=='am'}">上半段</option>
                            <option value="pm" th:selected="*{startDateFlag=='pm'}">下半段</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">结束日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="endDateStr" th:field="*{endDateStr}"
                               readonly class="layui-input date" />
                    </div>
                    <div class=" date-flag layui-input-inline">
                        <select name="endDateFlag" disabled>
                            <option value="am" th:selected="${leave.endDateFlag=='am'}">上半段</option>
                            <option value="pm" th:selected="${leave.endDateFlag=='pm'}">下半段</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">流程ID</label>
                <div class="layui-input-block">
                    <input type="text" name="processId" th:field="*{processId}"
                           placeholder="请输入流程ID" class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">请假天数</label>
                <div class="layui-input-block">
                    <input type="text" name="days" th:field="*{days}"
                           readonly class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">请假说明</label>
                <div class="layui-input-block">
                    <input type="text" name="remark" th:field="*{remark}"
                           readonly class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">附件</label>
                <div class="layui-input-block">

                    <input type="hidden" id="fileId" name="fileId" />
                    <div id="zyupload" class="layui-input"></div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit=""
                    lay-filter="leave-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="button" class="layui-btn layui-btn-sm" id="reject">
                <i class="layui-icon layui-icon-refresh"></i>
                驳回
            </button>
        </div>
    </div>
</form>
</body>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    layui.use(['form', 'jquery', 'laydate', 'dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;
        let url = pName + '/kq/leave/next/' + $('#processId').val();

        $('#reject').on('click', function(){
            url = pName + '/kq/leave/back/' + $('#processId').val();
            window.sendData(false);
            return false;
        });
        form.on('submit(leave-update)', function (data) {
            window.sendData(true);
            return false;
        });
        window.sendData = function (flag) {
            var callback = function(){
                $.ajax({
                    url: url,
                    data: JSON.stringify({"flag": flag, "auditId": $('#auditId').val()}),
                    dataType: 'json',
                    contentType: 'application/json',
                    type: 'post',
                    success: function (result) {
                        if (result.code == 1) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                top.layer.close(top.layer.getFrameIndex(parent.window.name));
                            });
                        } else {
                            layer.alert(result.msg, {icon: 2});
                        }
                    }
                })
            }
            userUtil.initUserSelect("auditId", "auditName", callback, "考勤")

        }
    });
</script>
</html>